import { ORDER_LIST } from '../actions/actionTypes'
const initState = {
  list: [],
  filterData: null,
  page: 0,
  isend: false
}

const getOrderDate = (state, action) => {
  console.log(action)
  console.log(123456)
  // if (action.currentPage == 0) {
  //   return { ...state, list: action.obj.data.poilist }
  // } else {
  //   let list = state.list
  //   return { ...state, list: list.concat(action.obj.data.poilist)}
  // }
  let _listData = []
  let _filterData = action.filterData || state.filterData
  let _page = action.toFirstPage ? 0 : state.page
  let _isend = false
  if (_page === 0) {
    _listData = action.obj.data.digestlist
  } else {
    _listData = state.list.concat(action.obj.data.digestlist)
  }
  _page = _page + 1
  if (_page > 3) {
    _isend = true
  }
  return {
    ...state,
    list: _listData,
    filterData: _filterData,
    page: _page,
    isend: _isend
  }
}
const orderReducer = (state = initState, action) => {
  switch (action.type) {
    case ORDER_LIST:
      return getOrderDate(state, action)
    default:
      return state
  }
}
export default orderReducer
